// 自定义按钮
export const toolbarIconsClass = {
  // 指定一个FontAawsome的图标类
  square : "fa-superscript", // x的n次方
  subscript: "fa-subscript", // 下标
};
export const  toolbarIconTexts = { 
  // 如果没有图标，则可以这样直接插入内容，可以是字符串或HTML标签
  equation: "公式", 
  parenthesis: "{[()]}", // 括号
  sqrt: "√￣", // 根号
  sigma: "∑", // 求和
  delta: "Δ", // 三角
  sin: "sinx", // 三角函数
  fractionalType: "1/4", // 分式
  integration: "∫", // 积分
}
export const toolbarCustomIcons = {
};
 // 自定义工具栏按钮的事件处理
export const toolbarHandlers = {
  // 平方
  square : function(cm, iocn, cursor, selection) {
    let content = "{" + selection + "} ^ {2}"
    let index = 1
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 公式
  equation : function(cm, iocn, cursor, selection) {
    let content = "```katex  \\displaystyle"+ selection +" ```"
    let index = 8
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 小括号 
  parenthesis : function(cm, iocn, cursor, selection) {
    let content = "\\left( "+ selection +" \\right)"
    let index = 7
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 根号
  sqrt : function(cm, iocn, cursor, selection) {
    let content = "\\sqrt {"+ selection +"}"
    let index = 7
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 求和
  sigma : function(cm, iocn, cursor, selection) {
    let content = "\\sum_{}^{} "
    let index = 6
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 下标
  subscript: function(cm, iocn, cursor, selection) {
    let content = "_{" + selection +"}"
    let index = 3
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 三角
  delta: function(cm, iocn, cursor, selection) {
    let content = "\\Delta "
    let index = 6
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 三角函数
  sin:  function(cm, iocn, cursor, selection) {
    let content = "\\sin " + selection;
    let index = 4
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 分式
  fractionalType: function(cm, iocn, cursor, selection) {
    let content = "\\frac{" + selection + "}{}"
    let index = 6
    handler(cm, iocn, cursor, selection, content, index)
  },
  // 积分
  integration: function(cm, iocn, cursor, selection) {
    let content = "\\int_{" + selection + "}^{}"
    let index = 6
    handler(cm, iocn, cursor, selection, content, index)
  },
};
// 鼠标悬浮提示信息
export const lang = {
  toolbar : {
    square : "n次方",  // 自定义按钮的提示文本，即title属性
    equation: "开启科学公式，块级公式: \\displaystyle ",
    sqrt: "根号",
    sigma: "求和",
    parenthesis: "括号: () [] {}",
    subscript: "公式下标",
    delta: "变化",
    sin: "三角函数, 例: sin=> \\sin",
    integration: "积分",
  }
};


// 插入的函数
var handler = function(cm, iocn, cursor, selection, content, index) {
  // 替换选中文本，如果没有选中文本，则直接插入
  cm.replaceSelection(content);
  console.log(iocn);
  // 如果当前没有选中的文本，将光标移到要输入的位置
  if(selection === "") {
    cm.setCursor(cursor.line, cursor.ch + index);
  }
};